import 'package:dio/dio.dart';
import 'package:enjoy_plus_flutter_7/utils/Request_Dio.dart';
import 'package:flutter/foundation.dart';
import 'package:image_picker/image_picker.dart';

import '../constants/index.dart';

sendCodeAPI(Map<String, dynamic> param) {
  return requestDio.get(HTTPPATH.USER_SEND_CODE, param: param);
}

userLoginAPI(Map<String, dynamic> data) {
  return requestDio.post(HTTPPATH.USER_LOGIN_CODE, data: data);
}

userInfoAPI() {
  return requestDio.get(HTTPPATH.USER_INFO);
}

updateUserApi(Map<String, dynamic> data) {
  return requestDio.put(HTTPPATH.USER_INFO, data: data);
}

uploadImgApi(XFile file, {bool isAvatar = true}) async {
  FormData formData = FormData.fromMap({
    'file': kIsWeb
        ? MultipartFile.fromBytes(
            await file.readAsBytes(),
            filename: file.name,
            contentType: DioMediaType('image', 'jpg'),
          )
        : MultipartFile.fromFileSync(
            file.path,
            filename: file.name,
            contentType: DioMediaType('image', 'jpg'),
          ),
    'type': isAvatar ? 'avatar' : null
  });
  return requestDio.upload(HTTPPATH.UPLOAD, data: formData);
}
